SQLite

class SQLite(context: Context, url: String, options: ConnectionPool.Options = ConnectionPool.Options(), val encoders: ValueEncoderRegistry = ValueEncoderRegistry()) : ISQLite(source)

SQLite class provides mechanisms to interact with a SQLite database on the Android platform. It implements Driver, Driver.Pool, and Driver.Transactional interfaces, offering functionalities such as connection pooling, executing queries, fetching data, and handling transactions.

The URL uses the same sqlx-style format as the other targets:

  • sqlite::memory: - Creates an in-memory database

  • sqlite:database.db / sqlite://database.db - Creates/opens a database file in the app's databases directory (see Context.getDatabasePath)

  • sqlite:///path/to/database.db - Uses an absolute path

  • sqlite:///path/to/database.db?mode=ro - Opens read-only. mode may be ro, rw (never creates), rwc or memory; without it the file is created when missing. cache is accepted but ignored: Android manages its own cache, and in-memory pools are limited to one connection anyway. Any other parameter (immutable, vfs, ...) cannot be honoured on Android and is rejected.

If the URL does not start with "sqlite:", it will be automatically prefixed.

Parameters

context

The Android Context to use for database operations.

url

The URL of the SQLite database to connect to.

options

Optional pool configuration, defaulting to ConnectionPool.Options.

encoders

Optional registry of value encoders to use for encoding query parameters.

Constructors

Link copied to clipboard
constructor(context: Context, url: String, options: ConnectionPool.Options = ConnectionPool.Options(), encoders: ValueEncoderRegistry = ValueEncoderRegistry())

Types

Link copied to clipboard
Link copied to clipboard
class AndroidTransaction(db: SQLiteDatabase, closeConnectionAfterTx: Boolean, val encoders: ValueEncoderRegistry, dispatcher: CoroutineDispatcher) : Transaction
Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val encoders: ValueEncoderRegistry

Functions

Link copied to clipboard
open suspend override fun acquire(): Result<Connection>
Link copied to clipboard
open suspend override fun begin(): Result<Transaction>
Link copied to clipboard
open suspend override fun close(): Result<Unit>
Link copied to clipboard
open suspend override fun execute(statement: Statement): Result<Long>
open suspend override fun execute(sql: String): Result<Long>
Link copied to clipboard
open suspend fun <T> fetchAll(statement: Statement, rowMapper: RowMapper<T>): Result<List<T>>
open suspend fun <T> fetchAll(sql: String, rowMapper: RowMapper<T>): Result<List<T>>
open suspend override fun fetchAll(statement: Statement): Result<ResultSet>
open suspend override fun fetchAll(sql: String): Result<ResultSet>
Link copied to clipboard
open suspend override fun migrate(supplier: () -> List<MigrationFile>, table: String, schema: String?, createSchema: Boolean, afterStatementExecution: suspend (Statement, Duration) -> Unit, afterFileMigration: suspend (Migration, Duration) -> Unit): Result<Migrator.Results>
open suspend override fun migrate(path: String, table: String, schema: String?, createSchema: Boolean, afterStatementExecution: suspend (Statement, Duration) -> Unit, afterFileMigration: suspend (Migration, Duration) -> Unit): Result<Migrator.Results>
open suspend override fun migrate(files: List<MigrationFile>, table: String, schema: String?, createSchema: Boolean, afterStatementExecution: suspend (Statement, Duration) -> Unit, afterFileMigration: suspend (Migration, Duration) -> Unit): Result<Migrator.Results>
Link copied to clipboard
open override fun poolIdleSize(): Int
Link copied to clipboard
open override fun poolSize(): Int
Link copied to clipboard
open suspend fun <T> transaction(f: suspend Transaction.() -> T): T
Link copied to clipboard
open suspend fun <T> transactionCatching(f: suspend Transaction.() -> T): Result<T>